package com.hfzy.ihk.web.freeswitchCall.vo;


import com.hfzy.ihk.web.freeswitchCall.context.EventSocketInitBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/** freeswitch 的网关
 * @Auther: Administrator
 * @Date: 2018/12/24 17:04
 * @Description:
 */
public class FreeswitchGateway {

    Logger logger= LoggerFactory.getLogger(FreeswitchGateway.class);

    //Contact字段,进行外呼的时候就要截取这部分
    private String contact;

    //contact字段中的 ip:prot(为了对比正在进行的通话)
    private String address ;

    //注册上来的user
    private String user;


    //总线路数
    private int totalLines;

    //已占用线路数
    private int busyLines;

    //可用线路数
    private int freeLines;



    //是否已经注册(1代表已经注册,0代表未注册)
    private String registered;

    //网关名称
    private String agent;

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public int getTotalLines() {
        return totalLines;
    }

    public void setTotalLines(int totalLines) {
        this.totalLines = totalLines;
    }

    public int getBusyLines() {
        return busyLines;
    }

    public void setBusyLines(int busyLines) {
        this.busyLines = busyLines;
    }

    public int getFreeLines() {
        return freeLines;
    }

    public void setFreeLines(int freeLines) {
        this.freeLines = freeLines;
    }

    public String getRegistered() {
        return registered;
    }

    public void setRegistered(String registered) {
        this.registered = registered;
    }

    public String getAgent() {
        return agent;
    }

    public void setAgent(String agent) {
        this.agent = agent;
    }

    public synchronized void increment(){

        busyLines++;

        freeLines=totalLines-busyLines;

       // logger.info("正式发起呼叫,当前{}分机已用线路{}可用线路:{},总线路数:{},所有分机总可用线路为{}",user,busyLines,freeLines,totalLines, EventSocketInitBean.getFreeLines().size());

    }

    public synchronized void decrement(){

        busyLines--;

        freeLines=totalLines-busyLines;

       // EventSocketInitBean.getFreeLines().add(this);

       // logger.info("用户挂机,当前{}分机已用线路{}可用线路:{},总线路数:{},所有分机总可用线路为{}",user,busyLines,freeLines,totalLines, EventSocketInitBean.getFreeLines().size());

    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "FreeswitchGateway{" +
                "contact='" + contact + '\'' +
                ", address='" + address + '\'' +
                ", user='" + user + '\'' +
                ", totalLines=" + totalLines +
                ", busyLines=" + busyLines +
                ", freeLines=" + freeLines +
                ", registered='" + registered + '\'' +
                ", agent='" + agent + '\'' +
                '}';
    }
}
